package com.weishaoying.example.web;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * @author WeiShaoying
 * @date 2018/4/3
 */
//@RestController
@RequestMapping(value = "/")
public class TestController {

    private Random random = new Random();

    @GetMapping()
    public String hello() {
        return "hello-" + random.nextInt(100000);
    }

    @GetMapping("/hi/{name}")
    public String hi(@PathVariable String name) {
        return String.format("hi,%s 您的工资是：%d", name, random.nextInt(10000));
    }

    @GetMapping(value = "/admin/queryAllUsers")
    public List<String> queryAllUsers() {
        List<String> userList = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            userList.add("User-" + random.nextInt(9999));
        }
        return userList;
    }

    @GetMapping(value = "/user/queryBooks")
    public List<String> queryBooks() {
        List<String> books = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            books.add("Book-" + random.nextInt(9999));
        }
        return books;
    }
}
